package com.gumbou.mis.controller.pos;

import com.gumbou.mis.pos.entity.PosCategory;
import com.gumbou.mis.pos.service.ICategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ：JunBao Huang
 * @description：CategoryController
 * @date ：2021/9/24 0:54
 */
@RestController
@RequestMapping("category")
@Api(value = "category", tags = "商品种类")
public class CategoryController {
    /**
     * 服务对象
     */
    @Autowired
    private ICategoryService categoryService;

    /**
     * 分页查询
     *
     * @param posCategory 筛选条件
     * @return 查询结果
     */
    @ApiOperation(value = "查询种类列表")
    @GetMapping("/list")
    public List<PosCategory> list(PosCategory posCategory) {
        return this.categoryService.queryAll(posCategory);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param posCategoryId 主键
     * @return 单条数据
     */
    @GetMapping("{posCategoryId}")
    public PosCategory getById(@PathVariable("posCategoryId") Integer posCategoryId) {
        return this.categoryService.queryById(posCategoryId);
    }

    /**
     * 新增数据
     *
     * @param posCategory 实体
     * @return 新增结果
     */
    @PostMapping
    public String add(@RequestBody PosCategory posCategory) {
        this.categoryService.insert(posCategory);
        return "ok";
    }

    /**
     * 编辑数据
     * @param posCategory 实体
     * @return 编辑结果
     */
    @PutMapping
    public String edit(@RequestBody PosCategory posCategory) {
        this.categoryService.update(posCategory);
        return "ok";
    }

    /**
     * 删除数据
     *
     * @param posCategoryId 主键
     * @return 删除是否成功
     */
    @DeleteMapping("/delete/{posCategoryId}")
    public Boolean deleteById(@PathVariable Integer posCategoryId) {
        return this.categoryService.deleteById(posCategoryId);
    }

}
